package com.maya.controller;



import javax.servlet.http.HttpSession;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.maya.model.Question;
import com.maya.model.User;
import com.maya.service.QuestionService;
import com.maya.service.UserService;


@Controller

public class FollowQuestionController  {

	@Autowired
	private QuestionService questionService;

	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping("/followquestion")
	public String followquestion (String qid,HttpSession session){
		
		User user = (User)session.getAttribute("currUser");
		
		Question question = questionService.get(new ObjectId(qid));

		if (null == user || null == question) {
			
			return "----fail: not a logined user---";
		}
		userService.followQuestion(user,question);

		return "OK";
	}

}
